<template>
  <div class="home-container">
    <!-- 欢迎卡片 -->
    <div class="welcome-card">
      <div class="welcome-content">
        <div class="welcome-text">
          <h1 class="welcome-title">欢迎回来！</h1>
          <p class="welcome-subtitle">今天是美好的一天，让我们开始工作吧</p>
        </div>
        <div class="welcome-icon">
          <el-icon size="48" color="#3498db"><Sunny /></el-icon>
        </div>
      </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-grid">
      <div class="stat-card" v-for="stat in stats" :key="stat.title">
        <div class="stat-icon" :style="{ background: stat.color }">
          <el-icon size="24" color="#fff">
            <component :is="stat.icon" />
          </el-icon>
        </div>
        <div class="stat-content">
          <h3 class="stat-title">{{ stat.title }}</h3>
          <p class="stat-value">{{ stat.value }}</p>
          <p class="stat-change" :class="stat.trend">
            <el-icon size="12">
              <component :is="stat.trend === 'up' ? 'ArrowUp' : 'ArrowDown'" />
            </el-icon>
            {{ stat.change }}
          </p>
        </div>
      </div>
    </div>

    <!-- 快速操作 -->
    <div class="quick-actions">
      <h2 class="section-title">快速操作</h2>
      <div class="actions-grid">
        <div
          class="action-card"
          v-for="action in quickActions"
          :key="action.title"
          @click="handleQuickAction(action)"
        >
          <div class="action-icon" :style="{ background: action.color }">
            <el-icon size="24" color="#fff">
              <component :is="action.icon" />
            </el-icon>
          </div>
          <div class="action-content">
            <h3 class="action-title">{{ action.title }}</h3>
            <p class="action-description">{{ action.description }}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 最近活动 -->
    <div class="recent-activities">
      <h2 class="section-title">最近活动</h2>
      <div class="activities-list">
        <div
          class="activity-item"
          v-for="activity in recentActivities"
          :key="activity.id"
        >
          <div class="activity-avatar">
            <el-avatar :size="40" :src="activity.avatar">
              <el-icon><User /></el-icon>
            </el-avatar>
          </div>
          <div class="activity-content">
            <p class="activity-text">
              <strong>{{ activity.user }}</strong> {{ activity.action }}
            </p>
            <p class="activity-time">{{ activity.time }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()

// 统计数据
const stats = ref([
  {
    title: '总用户数',
    value: '1,234',
    change: '+12%',
    trend: 'up',
    icon: 'User',
    color: 'linear-gradient(135deg, #3498db 0%, #2980b9 100%)'
  },
  {
    title: '今日访问',
    value: '567',
    change: '+8%',
    trend: 'up',
    icon: 'View',
    color: 'linear-gradient(135deg, #2ecc71 0%, #27ae60 100%)'
  },
  {
    title: '系统消息',
    value: '23',
    change: '-3%',
    trend: 'down',
    icon: 'Bell',
    color: 'linear-gradient(135deg, #f39c12 0%, #e67e22 100%)'
  },
  {
    title: '待处理任务',
    value: '45',
    change: '+5%',
    trend: 'up',
    icon: 'Edit',
    color: 'linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%)'
  }
])

// 快速操作
const quickActions = ref([
  {
    title: '添加用户',
    description: '创建新的用户账户',
    icon: 'Plus',
    color: 'linear-gradient(135deg, #3498db 0%, #2980b9 100%)',
    path: '/system/user'
  },
  {
    title: '系统设置',
    description: '配置系统参数',
    icon: 'Setting',
    color: 'linear-gradient(135deg, #2ecc71 0%, #27ae60 100%)',
    path: '/system'
  },
  {
    title: '数据导入',
    description: '批量导入数据',
    icon: 'Upload',
    color: 'linear-gradient(135deg, #f39c12 0%, #e67e22 100%)',
    path: '/test'
  },
  {
    title: '数据导出',
    description: '导出系统数据',
    icon: 'Download',
    color: 'linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%)',
    path: '/book'
  }
])

// 最近活动
const recentActivities = ref([
  {
    id: 1,
    user: '张三',
    action: '创建了新用户账户',
    time: '2分钟前',
    avatar: ''
  },
  {
    id: 2,
    user: '李四',
    action: '更新了系统设置',
    time: '5分钟前',
    avatar: ''
  },
  {
    id: 3,
    user: '王五',
    action: '导入了用户数据',
    time: '10分钟前',
    avatar: ''
  },
  {
    id: 4,
    user: '赵六',
    action: '修改了权限配置',
    time: '15分钟前',
    avatar: ''
  }
])

// 处理快速操作
const handleQuickAction = (action: any) => {
  ElMessage.success(`正在跳转到${action.title}`)
  router.push(action.path)
}
</script>

<style scoped>
.home-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* 欢迎卡片 */
.welcome-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 32px;
  color: white;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.welcome-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
  pointer-events: none;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
}

.welcome-text {
  flex: 1;
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px 0;
  letter-spacing: -0.025em;
}

.welcome-subtitle {
  font-size: 16px;
  margin: 0;
  opacity: 0.9;
  font-weight: 400;
}

.welcome-icon {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(10px);
}

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-content {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #64748b;
  margin: 0 0 8px 0;
  font-weight: 500;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 4px 0;
}

.stat-change {
  font-size: 12px;
  font-weight: 500;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-change.up {
  color: #10b981;
}

.stat-change.down {
  color: #ef4444;
}

/* 快速操作 */
.section-title {
  font-size: 20px;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 16px 0;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.action-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border-color: #3498db;
}

.action-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-content {
  flex: 1;
}

.action-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin: 0 0 4px 0;
}

.action-description {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

/* 最近活动 */
.activities-list {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid #f1f5f9;
}

.activity-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.activity-avatar {
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
}

.activity-text {
  font-size: 14px;
  color: #1e293b;
  margin: 0 0 4px 0;
}

.activity-time {
  font-size: 12px;
  color: #64748b;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .welcome-content {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }

  .welcome-title {
    font-size: 24px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .actions-grid {
    grid-template-columns: 1fr;
  }

  .stat-card,
  .action-card {
    padding: 16px;
  }
}

/* 动画效果 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.welcome-card,
.stat-card,
.action-card,
.activities-list {
  animation: fadeInUp 0.6s ease-out;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }
.stat-card:nth-child(4) { animation-delay: 0.4s; }
</style>
